<%@ page import="car.aistar.dto.TqxCarSelect" %><%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2020/9/22
  Time: 8:48 上午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--$("#page").load("${pageContext.request.contextPath}/jsp/page/indexCarpage.jsp?pageNow=1&pageSize=12&pageNums=${carInfoList.size()}");--%>
<%
    Integer pageNow = Integer.valueOf(request.getParameter("pageNow"));
    request.setAttribute("pageNow",pageNow);
    System.out.println("pageNow"+pageNow);
    Integer pageSize = Integer.valueOf(request.getParameter("pageSize"));
    request.setAttribute("pageSize",pageSize);
    Integer Nums = Integer.valueOf(request.getParameter("pageNums"));
    request.setAttribute("Nums",Nums);
    Integer pageNums = (int) Math.ceil(Nums*1.0/pageSize);
    request.setAttribute("pageNums",pageNums);
%>
<div class="container" style="text-align: center">
    <ul class="pagination">
        <li><a href="javascript:next_page(1)">首页</a></li>

        <c:if test="${pageNow<=1}">
            <li class="disabled"><a href="#">&laquo;</a></li>
        </c:if>

        <c:if test="${pageNow>1}">
            <li><a href="javascript:next_page(${pageNow-1})">&laquo;</a></li>
        </c:if>

        <c:if test="${pageNow+2<=pageNums}">
            <c:set var="endPage" value="${pageNow+2}"></c:set>
            <c:set var="startPage" value="${pageNow}"></c:set>
        </c:if>

        <c:if test="${pageNow+2>pageNums}">
            <c:set var="endPage" value="${pageNums}"></c:set>
            <c:set var="startPage" value="${pageNums-2}"></c:set>
        </c:if>
        <c:if test="${startPage<0}">
            <li <c:if test="${pageNow == 1}">class="active"</c:if></li> <a>1</a></li>
        </c:if>

        <c:if test="${startPage>0}">
            <c:forEach begin="${startPage}" end="${endPage}" var="v">
                <li <c:if test="${pageNow == v}">class="active"</c:if></li> <a href="javascript:next_page(${v})">${v}</a></li>
            </c:forEach>
        </c:if>
        <c:if test="${pageNow<pageNums}">
            <li><a href="javascript:next_page(${pageNow+1})">&raquo;</a></li>
        </c:if>

        <c:if test="${pageNow>=pageNums}">
            <li class="disabled"><a href="#">&raquo;</a></li>
        </c:if>


        <li><a href="javascript:next_page(${pageNums})">尾页</a></li>
        <li><a href="#">当前页${pageNow}/${pageNums}总页</a></li>
        <li><a style="padding: 0;border: none;margin-left: 2px"><input placeholder="跳转页" class="form-control" value="" id="toPage">

        </a></li>
        <li><a style="padding: 0;border: none"><button type="button" class="btn btn-info" onclick="to_page()">Go</button></a></li>
        <li><a style="padding: 0;border: none;margin-left: 2px">
            <select id="pageSizeSelect" onchange="page_size(this)" style="width: 180px" class="form-control">
                <option value="-1">===每页显示条数====</option>
                <c:forEach begin="2" end="16" var="num">
                    <option <c:if test="${num == pageSize}">selected</c:if> value="${num}">每页显示条数:${num}</option>
                </c:forEach>
            </select></a></li>
    </ul>
</div>

<input type="text"  id="path "class=" hidden" value="<%=request.getContextPath()%>">
<script>
    var path = $("#path").val()

    function to_page() {
        let pageto = $("#toPage").val();
        next_page(pageto);
    }
    function next_page(page){
        let size = $("#pageSizeSelect").val();
        if(size==-1||size==null)
            size=12
        $("#content").load(path+"/carDetail/index/carInfo.action",{pageNow:page,pageSize:size})
        // window.location= path+"/carDetail/index/carInfo.action?pageNow="+page+"&pageSize="+size;
    }

    function page_size(obj){
        // alert(obj.value)
        $("#content").load(path+"/carDetail/index/carInfo.action",{pageNow:1,pageSize:obj.value})
        // window.location= path+"/carDetail/index/carInfo.action?pageNow=1&pageSize="+obj.value;

    }
</script>